<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css" />
<body>
<form class="layui-form" lay-filter="component-form-group">
    <div class="mainBox  layui-card-body" style="padding: 0 0;">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">任务图标</label>
                <div class="layui-input-block" style="width: 60%;display: flex">
                    <input type="text" name="icon" value="{$inf.icon}" id="icon" lay-verify="required" autocomplete="off" placeholder="请选择任务图标" class="layui-input">
                    <a class="layui-btn" onclick="show()">选择</a>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">任务标题*</label>
                <div class="layui-input-block">
                    <input type="text" name="title" value="{$inf.title}" lay-verify="required" autocomplete="off" placeholder="请输入任务标题" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">Title(EN)*</label>
                <div class="layui-input-block">
                    <input type="text" name="e_title" value="{$inf.e_title}" lay-verify="required" autocomplete="off" placeholder="请输入Title(EN)" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">任务简介*</label>
                <div class="layui-input-block">
                    <input type="text" name="intro" value="{$inf.intro}" lay-verify="required" autocomplete="off" placeholder="请输入任务简介" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">Intro(EN)*</label>
                <div class="layui-input-block">
                    <input type="text" name="e_intro" value="{$inf.e_intro}" lay-verify="required" autocomplete="off" placeholder="请输入Intro(EN)" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">任务类型*</label>
                <div class="layui-input-block">
                    <select name="type" lay-verify="required">
                        <option value="1" {eq name="inf.type" value="1"}selected{/eq}>学习任务</option>
                        <option value="2" {eq name="inf.type" value="2"}selected{/eq}>其他任务</option>
                    </select>
                </div>
            </div>



            <div class="layui-form-item" {eq name="inf.hide" value = "1"} style="display: none;" {/eq}>
                <label class="layui-form-label">周期范围*</label>
                <div class="layui-input-block">
                    <select name="range" lay-filter="range1">
                        <option value="1" {eq name="inf.range" value="1"}selected{/eq}>每天</option>
                        <option value="2" {eq name="inf.range" value="2"}selected{/eq}>每周</option>
                        <option value="3" {eq name="inf.range" value="3"}selected{/eq}>每月</option>
                        <option disabled="" value="5" {eq name="inf.range" value="5"}selected{/eq}>一次性</option>
                    </select>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">奖励积分*</label>
                <div class="layui-input-block">
                    <input type="number" id="integral1" name="integral" value="{$inf.integral}" autocomplete="off" placeholder="请输入奖励积分" class="layui-input">
                </div>
            </div>



            <div class="layui-form-item" {eq name="inf.hide" value = "1"} style="display: none;" {/eq}>
                <label class="layui-form-label">奖励次数</label>
                <div class="layui-input-block">
                    <input type="number" name="num" id="num" value="{$inf.num}" value="1" autocomplete="off" placeholder="请输入奖励次数 0为不限制" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item" style="display:none;">
                <label class="layui-form-label">积分上限</label>
                <div class="layui-input-block">
                    <input type="number" name="upper_limit" readonly value="{$inf.upper_limit}"  value="1" autocomplete="off" placeholder="请输入积分上限 0为不限制" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item" style="display: none">
                <label class="layui-form-label">跳转链接</label>
                <div class="layui-input-block">
                    <input type="text" name="url" value="{$inf.url}" autocomplete="off" placeholder="请输入跳转链接" class="layui-input">
                </div>
            </div>
            <input type="hidden" name="id" value="{$inf.id}">
            {:token_field()}
        </div>
    </div>


    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{include file="_Fragment/javascript" /}
<script src="/static/common/jquery-3.6.0.min.js"></script>
<script>
    function show() {
        layer.open({
            type: 2,
            title: '选择图标',
            shade: 0.1,
            area: ['500px', '500px'],
            content: '/IntegralTask/showIcon'
        });
    }
    layui.use(['table', 'form', 'jquery', 'element'], function() {
        let form = layui.form;
        let table = layui.table;
        let $ = layui.jquery;
        form.render();

        form.on('select(range1)', function(data){
            var range = data.value;
            var data1 = form.val("component-form-group");
            var integral = data1.integral;
            var num = data1.num;
            var upper_limit = 0;
            if (range == 5) {
                upper_limit = integral;
            }else {
                if (integral != '' && num != '') {
                    if (range == 1) {
                        upper_limit =   integral * num * 7;
                    }else if(range == 2) {
                        upper_limit =   integral * num;
                    }else if(range == 3) {
                        upper_limit =   Math.round((integral * num) / 4);
                    }
                }
            }
            form.val("component-form-group", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                "upper_limit": upper_limit // "name": "value"
            });
        });

        $("#integral1").on('input',function(e){
            //获取input输入的值
            var data1 = form.val("component-form-group");
            var integral = e.delegateTarget.value;
            var num = data1.num;
            var range = data1.range;
            if (range == 5) {
                upper_limit = integral;
            }else {
                if (integral != '' && num != '') {
                    if (range == 1) {
                        upper_limit =   integral * num * 7;
                    }else if(range == 2) {
                        upper_limit =   integral * num;
                    }else if(range == 3) {
                        upper_limit =   Math.round((integral * num) / 4);
                    }
                }
            }
            form.val("component-form-group", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                "upper_limit": upper_limit // "name": "value"
            });
        });


        $("#num").on('input',function(e){
            //获取input输入的值
            var data1 = form.val("component-form-group");
            var integral = data1.integral;
            var num = e.delegateTarget.value;
            var range = data1.range;
            if (range == 5) {
                upper_limit = integral;
            }else {
                if (integral != '' && num != '') {
                    if (range == 1) {
                        upper_limit =   integral * num * 7;
                    }else if(range == 2) {
                        upper_limit =   integral * num;
                    }else if(range == 3) {
                        upper_limit =   Math.round((integral * num) / 4);
                    }
                }
            }
            form.val("component-form-group", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                "upper_limit": upper_limit // "name": "value"
            });
        });


        form.on('submit(user-save)', function(data) {
            let loading = layer.load();
            $.ajax({
                url: '/IntegralTask/modify',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    layer.close(loading);
                    if (result.status == 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>